import deepcopy from "deepcopy";
export default function dragEvent(dragItem, data,lastCheckItem) {
  //拖拽
  const onDragstart = (e, item) => {
    console.log(123, e);
    dragItem = deepcopy(item);
  };

  const onDragover = (e) => {
    e.preventDefault();
  };

  const onDrop = (e) => {
    // todo  将Drop方式改为监听点击组件和当前选中item,决定插值位置
    // console.log(45556, e, dragItem);
    dragItem.keyName = Math.random().toString(36).substr(2); //赋值随机数
    dragItem.propName = "";
    data.value.blocks.push(dragItem);
  };

  //formItem选中
  const onMouseenter = (e) => {
    // console.log(1233333,e);
  };
  const onMousedown = (e, item) => {
    // console.log(4444,lastCheckItem.value);
    clearFocus();
    e.stopPropagation();
    item.focus = true;
    lastCheckItem.value = deepcopy(item);

    // console.log("选中",lastCheckItem.value);
  };

  const clearFocus = () => {
    lastCheckItem.value = null;
    data.value.blocks.forEach((item) => {
      item.focus = false;
    });
  };
  return { onDragstart, onDragover, onDrop ,onMouseenter,onMousedown,clearFocus};
}
